<?php
/**
 * Created by PhpStorm.
 * User: simon
 * Date: 2016/8/17
 * Time: 16:55
 */

namespace App\Utils;


use p5\objects\PropertyUtils;
use p5\objects\TimeUtils;

class DataFormatter
{
    static public function toKindTimes(&$list, $propertyNames = [],$withMinute=true)
    {
        if (is_string($propertyNames)) {
            $propertyNames = [$propertyNames];
        }
        $size = count($list);
        for ($i = 0; $i < $size; $i++) {
            $item = $list[$i];
            foreach ($propertyNames as $property) {
                $time = PropertyUtils::get($item, $property);
                $time = TimeUtils::to_kind_time($time,$withMinute);
                if (is_array($item)) {
                    $item[$property] = $time;
                } else {
                    $item->$property = $time;
                }
            }
            $list[$i] = $item;
        }
    }
}